<?php
class SinglepageAction extends Action {
	public function index(){
		if(!isset($_SESSION['uid'])){
			$this->redirect('Index/login');
		}
		$m=M('Singlepage');
		$data=$m->order('id')->select();
		$this->assign('data',$data);
		$this->display();
	}
	
	public function create(){
		if(!isset($_SESSION['uid'])){
			$this->redirect('Index/login');
		}
		$m=M('Singlepage');
		$max=$m->max('id');
		$this->assign('max',$max+1);
		$this->display();
	}
	public function add(){
		if(!isset($_SESSION['uid'])){
			$this->redirect('Index/login');
		}
		if($this->isPost()){
			$m=M('Singlepage');
			$data=$m->create();
			if($m->add($data)){
				$this->success('成功','index');
			}else{
				$this->error('失败');
			}
		}
	}
	
	public function edit(){
		if(!isset($_SESSION['uid'])){
			$this->redirect('Index/login');
		}
		$m=M('Singlepage');
		$where['id']=$_GET['id'];
		$data=$m->where($where)->select();
		$this->assign('data',$data[0]);
		$this->display('update');
	}
	public function delete(){
		if(!isset($_SESSION['uid'])){
			$this->redirect('Index/login');
		}
		if ($this->isPost()) {
			$arr=$this->_post('menubox');
			$m=M('Singlepage');
			for($i=0;$i<count($arr);$i++){
				$where['id']=$arr[$i];
				$m->where($where)->delete();
			}
			$this->success('删除成功');
		}
	}
	public function update(){
		if(!isset($_SESSION['uid'])){
			$this->redirect('Index/login');
		}
		$m=M('Singlepage');
		$m->create();
		$m->save() or $this->error('失败');
		$this->success('成功','index');
	}
}

?>